package com.loveshare.imgshow.rest;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.loveshare.imgshow.entity.Doubanmz;
import com.loveshare.imgshow.entity.Music;
import com.loveshare.imgshow.entity.WebMusicInfo;
import com.loveshare.imgshow.service.ImgShowService;

/**
 * 
 * ClassName: ImgShowRest 
 * @Description: 异步获取图片展示控制器
 * @author 爱分享
 * @date 2017年12月20日
 */
@RestController
@RequestMapping(value="m")
public class MobileImgShowRest {

	@Autowired
	private ImgShowService imgShowService;
	
	/**
	 * 异步获取图片信息
	 * @return
	 */
	@RequestMapping(value="/mzSelfie_",method=RequestMethod.GET)
	public List<Doubanmz> mzImgShow(int page){
		List<Doubanmz> douBanMzs=imgShowService.getDoubanmzs("",5, page, 30);
		return douBanMzs;
	}
	
	/**
	 * 获取音乐信息
	 * @param keyword
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value="/ms",method=RequestMethod.GET)
	public List<WebMusicInfo> getMusic(@RequestParam String kd) throws UnsupportedEncodingException{
		
		String param = new String(kd.getBytes("ISO8859-1"), "UTF-8");
		List<Music> musics=imgShowService.getMusics(param, 1, 100);
		List<WebMusicInfo> list = new ArrayList<WebMusicInfo>();
		WebMusicInfo info = null;
		for (Music o : musics) {
			info = new WebMusicInfo();
			info.setAuthor(o.getAuthor());
			info.setTitle(o.getTitle());
			info.setUrl(o.getQnUrl());
			list.add(info);
		}
		return list;
	}
}
